# tidyverse
suppressPackageStartupMessages(library(tidyverse))
#gapminder
suppressPackageStartupMessages(library(gapminder))
#cowplot
suppressPackageStartupMessages(library(cowplot))
#plotly
suppressPackageStartupMessages(library(plotly))
#scales
suppressPackageStartupMessages(library(scales))
Welcome to the html version of the plotly figure. Here is the code that generates the plot:
#Creating new data set
#Mean gdpPercap for each continent by year
gap_gdp <- gapminder %>%
group_by(continent, year) %>%
summarise(mean_gdp = mean(gdpPercap)) %>%
arrange(year) #arrange by year to see if the order is maintained after reading
#plotting
plot <- ggplot(gap_gdp, aes(year, mean_gdp, color = continent)) +
geom_point() +
geom_smooth(method = lm, se = FALSE) +
scale_color_brewer(palette = "Dark2") + #changing the color of the continent
scale_y_continuous(labels = comma_format()) + #changes the y axis to comma values
xlab("Year") +
ylab("GDP per Capita") +
ggtitle("Increasing GDP With Time") +
theme_cowplot() +
theme(axis.text = element_text(size = 12)) #changes font size
And here is the code that generates the plotly version:
ggplotly(plot)